using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class DensityEllipseRender : MonoBehaviour
{
    LineRenderer line;
    public Vector2 radius;

    void Update()
    {
        if (transform.parent.GetComponent<Crown>().type == 0)
        {
            line = GetComponent<LineRenderer>();
            line.enabled = true;

            line.SetVertexCount(100 + 1);
            line.useWorldSpace = false;
            CreatePoints();
        }
        else
        {
            line.enabled = false;
        }
    }

    void CreatePoints()
    {
        float x;
        float y;
        float z = 0f;

        float angle = 20f;

        for (int i = 0; i < (100 + 1); i++)
        {
            x = Mathf.Sin(Mathf.Deg2Rad * angle) * radius.x;
            y = Mathf.Cos(Mathf.Deg2Rad * angle) * radius.y;

            line.SetPosition(i, new Vector3(x, y, z));

            angle += (360f / 100);
        }
    }
}
